package com.internetCafes.spms.web.toolbox.controller;


import com.internetCafes.spms.common.utils.entity.RR;
import com.internetCafes.spms.web.toolbox.entity.dto.website.WebsiteEditDto;
import com.internetCafes.spms.web.toolbox.entity.dto.website.WebsiteListDto;
import com.internetCafes.spms.web.toolbox.entity.vo.website.WebsiteAllVo;
import com.internetCafes.spms.web.toolbox.entity.vo.website.WebsiteListVo;
import com.internetCafes.spms.web.toolbox.entity.vo.website.WebsiteTypesVo;
import com.internetCafes.spms.web.toolbox.service.IWebsiteConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.internetCafes.spms.common.base.BaseWebController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 常用网站配置 前端控制器
 * </p>
 *
 * @author Zj
 * @since 2021-06-09
 */
@Api(tags = {">>>网站列表"})
@RestController
@RequestMapping("/toolbox/website")
public class WebsiteConfigController extends BaseWebController {

    @Autowired
    private IWebsiteConfigService iWebsiteConfigService;

    @ApiOperation("获取所有网站列表")
    @PostMapping("/all")
    @RequiresPermissions("toolbox:website:list")
    public RR<List<WebsiteAllVo>> all() {
        List<WebsiteAllVo> result = iWebsiteConfigService.all();
        return RR.successData(result);
    }

    @ApiOperation("获取网站列表配置")
    @PostMapping("/list")
    @RequiresPermissions("sys:website:list")
    public RR<List<WebsiteListVo>> list(@RequestBody WebsiteListDto dto) {
        List<WebsiteListVo> result = iWebsiteConfigService.list(dto);
        return RR.successData(result);
    }

    @ApiOperation("获取网站类型列表")
    @GetMapping("/types")
    @RequiresPermissions("sys:website:list")
    public RR<List<WebsiteTypesVo>> types() {
        List<WebsiteTypesVo> result = iWebsiteConfigService.types();
        return RR.successData(result);
    }

    @ApiOperation("编辑")
    @PostMapping("/edit")
    @RequiresPermissions("sys:website:update")
    public RR edit(@RequestBody WebsiteEditDto dto) {
        iWebsiteConfigService.edit(dto);
        return RR.success();
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    @RequiresPermissions("sys:website:save")
    public RR add(@RequestBody WebsiteEditDto dto) {
        iWebsiteConfigService.add(dto);
        return RR.success();
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    @RequiresPermissions("sys:website:delete")
    public RR delete(@PathVariable("id") Long id) {
        iWebsiteConfigService.delete(id);
        return RR.success();
    }
}
